


 for(j in 1:length(day.lengths)){


##get list of unique day numbers and trim unneccessary data based on bandwidth
days<-unique(stops.new.cpw$dayno)
days<-days[order(days, decreasing=F)]
front<- (1:day.lengths[j])
front
back<- ((length(days)-day.lengths[j]):length(days))
back
days<-days[-c(front,back)]##remove first bandwidth number of days (no days before it)
days
head(days)
length(days)


	for(i in 1:length(days)){


memo2<-days[i]


##define data set in desired bandwidth
stops.new.cpw2<-na.omit(stops.new.cpw[stops.new.cpw$dayno>=(memo2-day.lengths[j]) & stops.new.cpw$dayno<(memo2+day.lengths[j]),c("weapon.hit","dayno","lag.hit")])
#dim(stops.new.cpw2)


##define period indicator
stops.new.cpw2$period<-I(stops.new.cpw2$dayno>=memo2)
stops.new.cpw2$distance<-stops.new.cpw2$dayno-memo2


# ####local linear
 m<-lm(weapon.hit~period+distance+period*distance, data=stops.new.cpw2)
 results[[j]]$beta.loc.linear[i]<-m$coefficients["periodTRUE"]

####local linear^2
 m<-lm(weapon.hit~period+distance+period*distance+I(distance^2)+period*I(distance^2), data=stops.new.cpw2)
 results[[j]]$beta.loc.linear.sq[i]<-m$coefficients["periodTRUE"]

####local linear + lag
 m<-lm(weapon.hit~period+distance+period*distance+lag.hit, data=stops.new.cpw2)
 results[[j]]$beta.loc.linear.lag[i]<-m$coefficients["periodTRUE"]


####local linear + lag sq
 m<-lm(weapon.hit~period+distance+period*distance+lag.hit+I(distance^2)+period*I(distance^2), data=stops.new.cpw2)
 results[[j]]$beta.loc.linear.lag.sq[i]<-m$coefficients["periodTRUE"]

###diff in means
 m<-lm(weapon.hit~period, data=stops.new.cpw2)
 results[[j]]$beta.diff[i]<-m$coefficients["periodTRUE"]

####cubic
 m<-lm(weapon.hit~period+distance+period*distance+I(distance^2)+period*I(distance^2)+I(distance^3)+period*I(distance^3), data=stops.new.cpw2)
 results[[j]]$beta.cubic[i]<-m$coefficients["periodTRUE"]





}
save(results, file="output/placebo_meta_new2.Rdata")

}
